"use strict";
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
    var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
    if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
    else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
    return c > 3 && r && Object.defineProperty(target, key, r), r;
};
Object.defineProperty(exports, "__esModule", { value: true });
var core_1 = require("@angular/core");
var moment = require("moment");
var login_service_1 = require("../../lib/service/login.service");
var home_config_service_1 = require("../../lib/service/home/home-config.service");
var api_1 = require("../../../config/api");
var local_storage_service_1 = require("../../lib/service/local-storage.service");
var LoginData = /** @class */ (function () {
    function LoginData() {
    }
    return LoginData;
}());
exports.LoginData = LoginData;
var IndexHeaderComponent = /** @class */ (function () {
    function IndexHeaderComponent(loginService, router, homeConfigService, localStorageService) {
        this.loginService = loginService;
        this.router = router;
        this.homeConfigService = homeConfigService;
        this.localStorageService = localStorageService;
        this.account = '';
        this.password = '';
        this.hadLoginName = '';
        this.head_nav_show = false;
        this.aliyunOssOutputUrl = api_1.AliyunOssOutputUrl;
    }
    IndexHeaderComponent.prototype.ngOnInit = function () {
        this.getHomeConfig();
        var auth = this.localStorageService.getUserInfo();
        if (!!auth) {
            this.checkLoginInfo(auth);
        }
    };
    // 检查登录信息 查看是否过期
    IndexHeaderComponent.prototype.checkLoginInfo = function (auth) {
        // 创建时间
        var time = parseInt(auth.time, 10);
        // 过期时间
        var expireTime = time + 3600;
        // 当前时间
        var nowTime = parseInt(moment().format('X'), 10);
        if (expireTime < nowTime) {
            alert("登录信息过期，请重新登录");
            this.localStorageService.clearAll();
            this.hadLoginName = '';
            this.router.navigate(['/home/index']);
            return false;
        }
        else {
            this.hadLoginName = auth.nick_name;
        }
    };
    IndexHeaderComponent.prototype.getHomeConfig = function () {
        var _this = this;
        this.homeConfigService.getHomeConfig().subscribe(function (res) {
            if (res.code === 2000) {
                _this.homeConfig = res.data;
            }
            else {
                alert(res.code + ',' + res.message);
            }
        });
    };
    IndexHeaderComponent = __decorate([
        core_1.Component({
            selector: 'app-index-header',
            templateUrl: './index-header.component.html',
            styleUrls: ['./index-header.component.scss'],
            providers: [
                login_service_1.LoginService,
                home_config_service_1.HomeConfigService,
                local_storage_service_1.LocalStorageService
            ]
        })
    ], IndexHeaderComponent);
    return IndexHeaderComponent;
}());
exports.IndexHeaderComponent = IndexHeaderComponent;
